LanguageManager = {}

local m_language_type = nil

function LanguageManager.SetSelectType(type)
    m_language_type = type
end

function LanguageManager.GetSelectType()
    return m_language_type
end

function LanguageManager.GetLanguageType()
    if m_language_type == nil then
        m_language_type = LanguageMgr.language
    end
    return m_language_type
end

function LanguageManager.DownloadBranchRes(type)
    LanguageMgr:StartDownloadBranchRes(type)
end

--资源下载提示
function LanguageManager.ShowDownloadTips(size)
    local str = "开启分支需要下载资源，是否确认下载资源"
    local str1 = string.format("资源大小：%.1fM", size/1024)
    local sureClick = function()
        -- gameMgr:StartDownLoadBranch()
        local tp = LanguageManager.GetSelectType()
        LanguageMgr:StartDownloadBranchRes(tp)
    end

    local cancelClick = function()
    end
    logicMgr.UIShowManager.ShowCommonConfirm(str, str1, sureClick, cancelClick)
end

function LanguageManager.DownloadFinish()
    local str = "资源下载完成，是否立即重新加载游戏？"
    local str1 = ""

    local sureClick = function()
        LanguageManager.StartChangeLanguage()
        Game.ResetStart(false)
    end
    local cancelClick = function()
    end
    logicMgr.UIShowManager.ShowCommonConfirm(str, str1, sureClick, cancelClick)
end

function LanguageManager.DoChangeLanguage()
    local str = "切换语言需要重新加载游戏，是否确认切换语言版本"
    local str1 = ""

    local sureClick = function()
        LanguageManager.StartChangeLanguage()
        Game.ResetStart(false)
    end
    local cancelClick = function()
    end
    logicMgr.UIShowManager.ShowCommonConfirm(str, str1, sureClick, cancelClick)
end

function LanguageManager.ShowAssetsDeficiencyTips()
    local str = "繁体版本资源不足，是否继续下载资源"
    local str1 = ""

    local sureClick = function()
        LanguageMgr:StartDownloadBranchRes()
    end
    local cancelClick = function()
    end
    logicMgr.UIShowManager.ShowCommonConfirm(str, str1, sureClick, cancelClick)
end

function LanguageManager.StartChangeLanguage()
    UIPackage.RemoveAllPackages()
    local type = LanguageManager.GetSelectType()
    if type == nil then
        type = UnityEngine.PlayerPrefs.GetInt("Language_Type", 0)
    end
    LanguageMgr:ChangeLanguage(type)
    m_language_type = nil
end

function LanguageManager.InitLanguage()
    local type = UnityEngine.PlayerPrefs.GetInt("Language_Type", 0)
    YanhuaMMO.LuaHelper.GetLanguageMagnager():ChangeLanguage(type)
end

function LanguageManager.ShowDownLoadProcess(count)
    showUI(PanelResNames.UIDownLoad, count)
end

function LanguageManager.RefreshDownload(name, index)
    local download = CtrlManager.GetCtrl(PanelNames.UIDownLoad)
    if download then
        download.RefreshDownload(name, index)
    end
end

return LanguageManager